

<?php
$id=$_POST['id'];
$pos = $_POST['pos'];
$page_name = $_POST['page_name'];
$file=gmdate('YmdHis').$_FILES["upload"]["name"] ;
$url = $_POST['url'];
$authorised = $_POST['authorised'];
	
if(isset($_POST['save_add']))
{
	
	move_uploaded_file($_FILES["upload"]["tmp_name"],"../uploads/".$file);
	

	
			mysql_query("insert into right_ad(`posttion`, `page_id`, `upload_file`, `url`, `active_status`, `created_datetime`) values ('$pos', '$page_name','".$file."','$url','$authorised', now() )");	
		
		
		echo "<script>window.location='index.php?tc=add_right_ads&_s=1'</script>";
	
	
}
if($_POST['Update']=='Update')
{
	
	
	//$q = mysql_fetch_array(mysql_query("select upload_file  from  right_ad where id='".$_POST['hid']."'"));
	
	/*if($_FILES["upload"]["name"]=="")
	{
		 $file=$q['upload_file'];	
	
	}
	
	if($_FILES["upload"]["name"]!="")
	{
		
	 $path ="../uploads/".$q["upload_file"];
	  
	 @unlink($path);
	 $file=gmdate('YmdHis').$_FILES["upload"]["name"] ;
     move_uploaded_file($_FILES["upload"]["tmp_name"],"../uploads/".$file);

	}*/

	
mysql_query("update right_ad set posttion ='$pos', url='$url', active_status='$authorised', modified_datetime=now() where id='".$_POST['hid']."'") or die(mysql_error());
	echo "<script>window.location='index.php?tc=view_right_ads';</script>";
}

$query = mysql_query("select * 
					 from right_ad where id='".$_REQUEST['_d']."'") or die(mysql_error());

$res = mysql_fetch_array($query);

if($res["active_status"] == 0) {
	$deactive_status = "checked";
}
else {
	$active_status = "checked";
}
?>

<table border="0" width="100%" align="center">
<tr>
	<td width="46%" align="left"><span style="color:#1B78B7; font-size:14px; font-weight:bold">
    Map Ads</span>&nbsp; 
	<!--<input type="button" name="addnew" value="Add New" onclick="return show();" />-->
	</td>
	<td width="40%" align="right" class="font12">
    <a href="index.php?tc=view_right_ads" class="font12"><?php echo $text;?> View Ads</a></td>
</tr>
<tr>
	<td background="images/topline.gif" colspan="3" height="11"></td>
</tr>    
</table>
<form name="formPage" method="post" action="#"  enctype="multipart/form-data">
<table width="99%" align="center" border="0"  class="list">

<tr>
	<td align="right" width="250">Position*</td>
    <td align="left">
    <select name="pos" id="pos">
    <option value="top">Top</option>
    <option value="bottom">Bottom</option>
    <script language="javascript">
	document.formPage.pos.value="<?php echo $res['posttion'] ?>";
	</script>
    </select>
    
    </td>
</tr>
<tr>
  <td align="right" width="150">Url :</td>
  <td align="left"><input type="text" name="url" value="<?php echo $res['url']?>" /></td>
  
</tr>
<tr>
  <td align="right" width="150">Status :</td>
  <td align="left">
  <input name="authorised" type="radio"  value=1 <?php echo $active_status;?> />&nbsp;Active&nbsp;&nbsp;
  <input  name="authorised" type="radio" value=0 <?php echo $deactive_status;?>/>&nbsp;Deactive</td>
</tr>
<tr>
	<td align="right" width="150"></td>
    <td align="left">
    <input name="hid" id="hid" type="hidden" value="<?php echo $res['id'];?>"/>
     <?php if($res['id']=="")
	{?>
    <input type="submit" value="Submit" name="save_add">&nbsp;<input type="reset" name="reset" value="Clear" />
    <?php }
	else
	{ ?>
    <input type="submit" value="Update" name="Update">&nbsp;<input type="reset" name="reset" value="Clear" />
	<?php }  ?>
	
    </td>
</tr>
</table>
</form>